package com.icexxx.icemock.mock;

import com.icexxx.icemock.util.IceCactus;
import com.icexxx.icemock.util.IceMockUtil;
import com.icexxx.iceword.IceWordUtil;

import cn.hutool.core.util.RandomUtil;

public class NameMock implements IceMock {

	@Override
	public String mock(Integer minVal, Integer maxVal, Integer minWidth, Integer maxWidth, String enums, String key) {
		StringBuilder sb = new StringBuilder();
		if (minWidth == null) {
			minWidth = 2;
		}
		if (minWidth < 2) {
			minWidth = 2;
		}
		if (maxWidth == null) {
			maxWidth = 3;
		}
		if (maxWidth > 20) {
			maxWidth = 20;
		}
		final String wordHoneycomb = IceWordUtil.frequency();
		int wordHoneycombLength = wordHoneycomb.length();
		int widthFullName = RandomUtil.randomInt(minWidth, maxWidth + 1);
		String randomFamilyName = IceWordUtil.randomFamilyName();
		if (maxWidth == 2) {
			String simpleFamilyName = IceWordUtil.simpleFamilyName();
			int simpleFamilyNameLength = simpleFamilyName.length();
			int simpleFamilyNameIndex = RandomUtil.randomInt(simpleFamilyNameLength);
			randomFamilyName = simpleFamilyName.substring(simpleFamilyNameIndex, simpleFamilyNameIndex + 1);
		}
		int widthBaseName = widthFullName - randomFamilyName.length();
		if (randomFamilyName.length() == 2 && widthBaseName == 0) {
			widthBaseName++;
		}
		String cactus = IceCactus.cactus();
		sb.append(randomFamilyName);
		for (int i = 0; i < widthBaseName; i++) {
			sb.append(IceMockUtil.genWord(wordHoneycomb, wordHoneycombLength, cactus));
		}
		return sb.toString();
	}

}
